package com.vay.de.dang.online.web;

import android.app.Activity;
import android.content.Context;

import com.vay.de.dang.online.view.DialogRequest;

public abstract class ReqCallback {

    private Context mContext;
    private String mHintText;
    private boolean mShowLoading;
    private DialogRequest mDialog;

    public ReqCallback() {
        this(null);
    }

    public ReqCallback(Context context) {
        this.mContext = context;
        this.mHintText = "Loading...";
    }

    public ReqCallback showDialog(boolean show) {
        mShowLoading = show;
        return this;
    }

    public ReqCallback showText(String text) {
        mHintText = text;
        return this;
    }

    public void start() {
        try {
            if (mShowLoading && mDialog == null && (mContext instanceof Activity)) {
                mDialog = new DialogRequest(mContext);
                mDialog.showText(mHintText);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void end() {
        if (mDialog != null) {
            mDialog.dismiss();
            mDialog = null;
        }
    }

    public void error(ReqResult error){

    }

    public abstract void callback(ReqResult value);
}
